import { memphis, Memphis } from 'memphis-dev';

(async function () {
    let memphisConnection: Memphis | null = null;

    try {
        memphisConnection = await memphis.connect({
            host: 'broker.youling.io',
            username: 'youling',
            password: 'Youling@790313',
            accountId: 1
        });

        const producer = await memphisConnection.producer({
            stationName: 'demo',
            producerName: 'demosdfdf'
        });

        await producer.produce({
            message: Buffer.from("Message: Hello worldsdfsdf fsdfsd"), // you can also send JS object - {}
            asyncProduce: true
        });

        memphisConnection.close();
    } catch (ex) {
        console.log(ex);
        if (memphisConnection) memphisConnection.close();
    }
})();
